package forminrecipe.GUI;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import forminrecipe.core.Core;
import forminrecipe.data.*;

public class GUI extends JFrame {
	private JPanel mainPanel;
	private BrowserPanel browserPanel;
	private RecipePanel recipePanel;
	private ListPanel listPanel;
	private BoxLayout mainBoxLayout;
	private Core coreRef;
	private OptionPanel optionPanel;

	public GUI(Core core, SQLSettings sqlSet){
		coreRef=core;

		//main panel
		mainPanel = new JPanel();
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
		this.setContentPane(mainPanel);
		
		this.setSize(constants.GUI_WINDOW_WIDTH,constants.GUI_WINDOW_HEIGHT);
		//this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setTitle(constants.WINDOW_TITLE);
		
		//3 main panels browser, recipe and list
		browserPanel = new BrowserPanel(coreRef,this);
		recipePanel= new RecipePanel(coreRef);
		listPanel= new ListPanel(coreRef);
		browserPanel.setBounds(0, 0,constants.GUI_BROWSER_PANEL_WIDTH, constants.GUI_BROWSER_PANEL_HEIGHT);
		recipePanel.setBounds(constants.GUI_BROWSER_PANEL_WIDTH, 0, constants.GUI_RECIPE_PANEL_WIDTH, constants.GUI_RECIPE_PANEL_HEIGHT);
		listPanel.setBounds(constants.GUI_BROWSER_PANEL_WIDTH+constants.GUI_RECIPE_PANEL_WIDTH,0,constants.GUI_LIST_PANEL_WIDTH,constants.GUI_LIST_PANEL_HEIGHT);
		
		mainPanel.add(browserPanel);
		mainPanel.add(recipePanel);
		//mainPanel.add(listPanel);
		
		optionPanel = new OptionPanel(sqlSet,coreRef);
		//mainPanel.add(optionPanel);
		
		this.setVisible(true);
	}
	
	public void saveRecipePassToRecipe(){
		recipePanel.saveRecipePassFromBrowser();	
	}
	public void addListGUI(String item){
		listPanel.addItemToList(item);
	}
	public void addRecipeListGUI(RecipeData recipeData){
		browserPanel.addRecipeToList(recipeData);
	}
	public void diplayRecipeGUI(RecipeData recipeData){
		recipePanel.displayRecipe(recipeData);
	}
	public void addCatagoryGUI(String catagory){
		recipePanel.addCatagory(catagory);
	}

	public void resetRecipeFields(){
		recipePanel.resetAllFields();
	}
	public void setFeildsEditability(boolean bool){
		recipePanel.setFeildsEditability(bool);
	}
	public void setSelectedRecipe(int index){
		browserPanel.setSelectedRecipe(index);	
	}
	public void addIngredientGUI(String quantity, String units, String item){
		//todo - pass info to gui component for displaying
	}
	public void refreshGUI(){
		browserPanel.refresh();
	}

	public void displayRecipe(RecipeData recipeData) {
		// TODO Auto-generated method stub
		recipePanel.displayRecipe(recipeData);
		
	}
}
